package UI_admin;

import GestionBilleterie.Vendeur;
import GestionPlannification.Piece;
import java.awt.GridLayout;
import java.util.List;

/**
 *
 * @author Elsa Ferrare, Alexandre Becquet
 */
public class Frame_administration extends javax.swing.JFrame {

    /** Creates new form Frame_administration */
    public Frame_administration() {
        initComponents();
        this.chargerlesPieces();
        List<Vendeur> lesVendeurs = Vendeur.findEntities();
        for (int i = 0; i < lesVendeurs.size(); i++) {
            this.jComboBoxVendeurs.addItem(lesVendeurs.get(i));
        }
    }

    void chargerlesPieces(){
        this.jComboBoxPieces.removeAllItems();
        List<Piece> lesPieces = Piece.findEntities();
        for (int i = 0; i < lesPieces.size(); i++) {
            this.jComboBoxPieces.addItem(lesPieces.get(i));
        }
    }

    void fermerPanel() {
        this.jPanel1.removeAll();
        this.jPanel1.revalidate();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBoxPieces = new javax.swing.JComboBox();
        jButtonEditerPiece = new javax.swing.JButton();
        jButtonVoirReservation = new javax.swing.JButton();
        jButtonNouvellePiece = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JSeparator();
        jLabel4 = new javax.swing.JLabel();
        jButtonEditVendeur = new javax.swing.JButton();
        jComboBoxVendeurs = new javax.swing.JComboBox();
        jButtonNewVendeur = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButtonEditerPiece.setText("Editer Piece");
        jButtonEditerPiece.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEditerPieceActionPerformed(evt);
            }
        });

        jButtonVoirReservation.setText("Voir les Reservations");
        jButtonVoirReservation.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonVoirReservationActionPerformed(evt);
            }
        });

        jButtonNouvellePiece.setText("Nouvelle Piece");
        jButtonNouvellePiece.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonNouvellePieceActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 506, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 413, Short.MAX_VALUE)
        );

        jScrollPane1.setViewportView(jPanel1);

        jLabel2.setText("Pièces :");

        jLabel3.setText("Clients :");

        jButton2.setText("Voir les Clients");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel4.setText("Vendeurs :");

        jButtonEditVendeur.setText("Editer Vendeur");
        jButtonEditVendeur.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEditVendeurActionPerformed(evt);
            }
        });

        jButtonNewVendeur.setText("Nouveau Vendeur");
        jButtonNewVendeur.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonNewVendeurActionPerformed(evt);
            }
        });

        jButton1.setText("Mise à jour");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton1))
                    .addComponent(jComboBoxPieces, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonEditerPiece)
                    .addComponent(jButtonNouvellePiece)
                    .addComponent(jButtonVoirReservation)
                    .addComponent(jLabel3)
                    .addComponent(jButton2)
                    .addComponent(jLabel4)
                    .addComponent(jComboBoxVendeurs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonEditVendeur)
                    .addComponent(jButtonNewVendeur)
                    .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 488, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 415, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jComboBoxPieces, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(7, 7, 7)
                .addComponent(jButtonEditerPiece)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonVoirReservation)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonNouvellePiece)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jComboBoxVendeurs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonEditVendeur)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonNewVendeur)
                .addContainerGap(91, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonEditerPieceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEditerPieceActionPerformed
        // TODO add your handling code here:
        this.jPanel1.removeAll();
        Panel_Piece panPiece = new Panel_Piece(this, (Piece) this.jComboBoxPieces.getSelectedItem());
        this.jPanel1.setLayout(new GridLayout(1, 1));
        this.jPanel1.add(panPiece);
        this.jPanel1.revalidate();
}//GEN-LAST:event_jButtonEditerPieceActionPerformed

    private void jButtonVoirReservationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVoirReservationActionPerformed
        // TODO add your handling code here:
        this.jPanel1.removeAll();
        Panel_reservation panReservation = new Panel_reservation((Piece) this.jComboBoxPieces.getSelectedItem());
        this.jPanel1.setLayout(new GridLayout(1, 1));
        this.jPanel1.add(panReservation);
        this.jPanel1.revalidate();
}//GEN-LAST:event_jButtonVoirReservationActionPerformed

    private void jButtonNouvellePieceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNouvellePieceActionPerformed
        // TODO add your handling code here:
        this.jPanel1.removeAll();
        Panel_Piece panPiece = new Panel_Piece(this);
        this.jPanel1.setLayout(new GridLayout(1, 1));
        this.jPanel1.add(panPiece);
        this.jPanel1.revalidate();
    }//GEN-LAST:event_jButtonNouvellePieceActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        this.jPanel1.removeAll();
        Panel_client panClient = new Panel_client();
        this.jPanel1.setLayout(new GridLayout(1, 1));
        this.jPanel1.add(panClient);
        this.jPanel1.revalidate();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButtonEditVendeurActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEditVendeurActionPerformed
        this.jPanel1.removeAll();
        Panel_Vendeur panVendeur = new Panel_Vendeur((Vendeur)this.jComboBoxVendeurs.getSelectedItem());
        this.jPanel1.setLayout(new GridLayout(1, 1));
        this.jPanel1.add(panVendeur);
        this.jPanel1.revalidate();
}//GEN-LAST:event_jButtonEditVendeurActionPerformed

    private void jButtonNewVendeurActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNewVendeurActionPerformed
        this.jPanel1.removeAll();
        Panel_Vendeur panVendeur = new Panel_Vendeur();
        this.jPanel1.setLayout(new GridLayout(1, 1));
        this.jPanel1.add(panVendeur);
        this.jPanel1.revalidate();
    }//GEN-LAST:event_jButtonNewVendeurActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        fermerPanel();
        this.chargerlesPieces();
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Frame_administration().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButtonEditVendeur;
    private javax.swing.JButton jButtonEditerPiece;
    private javax.swing.JButton jButtonNewVendeur;
    private javax.swing.JButton jButtonNouvellePiece;
    private javax.swing.JButton jButtonVoirReservation;
    private javax.swing.JComboBox jComboBoxPieces;
    private javax.swing.JComboBox jComboBoxVendeurs;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator3;
    // End of variables declaration//GEN-END:variables

}
